

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/favicon.png">
  <link rel="icon" type="image/png" href="/img/favicon.png">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="MEUSA">
  <meta name="keywords" content="">
  <title>Nav2D插件工作原理 - MBLOG</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/railscasts.min.css" />
    
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.2.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>MBLOG</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/img/bg2.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container page-header text-center fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-10-29 20:50" pubdate>
        2020年10月29日 晚上
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      940 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      15
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto" id="post">
            <!-- SEO header -->
            <h1 style="display: none">Nav2D插件工作原理</h1>
            
            <div class="markdown-body" id="post-body">
              <h1 id="Nav2D插件工作原理"><a href="#Nav2D插件工作原理" class="headerlink" title="Nav2D插件工作原理"></a>Nav2D插件工作原理</h1><h2 id="大致概括"><a href="#大致概括" class="headerlink" title="大致概括"></a>大致概括</h2><p>该插件利用unity原生的navigation，对2d场景上的物体进行坐标转换建立对应的3d collider，然后调用navigation的bake进行navmesh的制作，也就是对unity原生navigation进行了一层套壳。<br>在寻路时，也是先建立2d对应的3d场景（collider、agent、obstacle等），将寻路目标点转换成三维坐标转递给agent，每帧将agent的坐标同步到2d中对应的物体。</p>
<h2 id="建立NavMesh"><a href="#建立NavMesh" class="headerlink" title="建立NavMesh"></a>建立NavMesh</h2><p>代码文件在editor中。<br>主要工作于其中的Navigation2D.cs中完成：</p>
<ul>
<li><code>BakeNavMesh2D()</code>中进行NavMesh的烘培。<br>首先根据2d中的静态collider建立对应的3d collider<div class="hljs"><pre><code class="hljs reasonml"><span class="hljs-comment">// create a temporary parent GameObject</span>
        var obj = <span class="hljs-keyword">new</span> <span class="hljs-constructor">GameObject()</span>;
        <span class="hljs-comment">// find all static box colliders, add them to projection</span>
        <span class="hljs-constructor">AddBoxCollider2Ds(<span class="hljs-params">obj</span>.<span class="hljs-params">transform</span>)</span>;
        <span class="hljs-comment">// find all static circle colliders, add them to projection</span>
        <span class="hljs-constructor">AddCircleCollider2Ds(<span class="hljs-params">obj</span>.<span class="hljs-params">transform</span>)</span>;
        <span class="hljs-comment">// find all static polygon colliders, add them to projection</span>
        <span class="hljs-constructor">AddPolygonCollider2Ds(<span class="hljs-params">obj</span>.<span class="hljs-params">transform</span>)</span>;
        <span class="hljs-comment">// find all edge polygon colliders, add them to projection</span>
        <span class="hljs-constructor">AddEdgeCollider2Ds(<span class="hljs-params">obj</span>.<span class="hljs-params">transform</span>)</span>;
        <span class="hljs-comment">// find all tilemap colliders, add them to projection</span>
#<span class="hljs-keyword">if</span> UNITY_2017_2_OR_NEWER
        <span class="hljs-constructor">AddTilemapCollider2Ds(<span class="hljs-params">obj</span>.<span class="hljs-params">transform</span>)</span>;
#endif

<span class="hljs-comment">// min and max point from 2D colliders projected to 3D.</span>
        <span class="hljs-comment">// (scanning through 3D colliders doesn&#x27;t work well because the polygon</span>
        <span class="hljs-comment">//  GameObjects are pure meshes without colliders)</span>
        var cols = GameObject.FindObjectsOfType&lt;Collider2D&gt;<span class="hljs-literal">()</span>;
        <span class="hljs-keyword">if</span> (cols.Length &gt; <span class="hljs-number">0</span>)
        &#123;
            var min = <span class="hljs-keyword">new</span> <span class="hljs-constructor">Vector2(Mathf.Infinity, Mathf.Infinity)</span>;
            var max = -min;
            foreach (var c <span class="hljs-keyword">in</span> cols)
            &#123;
                var minmax = NavMeshUtils2D.<span class="hljs-constructor">AdjustMinMax(<span class="hljs-params">c</span>, <span class="hljs-params">min</span>, <span class="hljs-params">max</span>)</span>;
                min = minmax<span class="hljs-literal">[<span class="hljs-number">0</span>]</span>;
                max = minmax<span class="hljs-literal">[<span class="hljs-number">1</span>]</span>;
            &#125;</code></pre></div></li>
<li>建立地面<div class="hljs"><pre><code class="hljs maxima">// create ground (<span class="hljs-built_in">cube</span> instead of plane because it has unit size)
            // (pos between <span class="hljs-built_in">min</span> <span class="hljs-keyword">and</span> <span class="hljs-built_in">max</span>; scaled to fit <span class="hljs-built_in">min</span> <span class="hljs-keyword">and</span> <span class="hljs-built_in">max</span> * <span class="hljs-built_in">scale</span>)
            // note: <span class="hljs-built_in">scale</span>.y=<span class="hljs-number">0</span> so that *navmeshExtends doesn&#x27;t make it too high
            <span class="hljs-built_in">var</span> <span class="hljs-built_in">go</span> = GameObject.CreatePrimitive(PrimitiveType.Cube);
            <span class="hljs-built_in">go</span>.name = <span class="hljs-string">&quot;Ground&quot;</span>; // <span class="hljs-keyword">for</span> debugging
            <span class="hljs-built_in">go</span>.isStatic = <span class="hljs-literal">true</span>;
            <span class="hljs-built_in">go</span>.<span class="hljs-built_in">transform</span>.parent = obj.<span class="hljs-built_in">transform</span>;
            <span class="hljs-built_in">float</span> w = <span class="hljs-built_in">max</span>.x - <span class="hljs-built_in">min</span>.x;
            <span class="hljs-built_in">float</span> h = <span class="hljs-built_in">max</span>.y - <span class="hljs-built_in">min</span>.y;
            <span class="hljs-built_in">go</span>.<span class="hljs-built_in">transform</span>.<span class="hljs-built_in">position</span> = <span class="hljs-built_in">new</span> Vector3(<span class="hljs-built_in">min</span>.x + w/<span class="hljs-number">2</span>, -<span class="hljs-number">0.</span>5f, <span class="hljs-built_in">min</span>.y + h/<span class="hljs-number">2</span>);
            <span class="hljs-built_in">go</span>.<span class="hljs-built_in">transform</span>.localScale = <span class="hljs-built_in">new</span> Vector3(w, <span class="hljs-number">0</span>, h) * navmeshExtends;</code></pre></div></li>
<li>调用Unity的NavMeshBuilder进行NavMesh生成<div class="hljs"><pre><code class="hljs reasonml"><span class="hljs-comment">// bake navmesh asynchronously, clear mesh</span>
        UnityEditor.AI.NavMeshBuilder.<span class="hljs-constructor">BuildNavMeshAsync()</span>; <span class="hljs-comment">// Async causes weird results</span>
        <span class="hljs-keyword">if</span> (gizmesh != null) gizmesh.<span class="hljs-constructor">Clear()</span>;
        needsRebuild = <span class="hljs-literal">true</span>; <span class="hljs-comment">// rebuild as soon as async baking is finished</span>

        <span class="hljs-comment">// delete the gameobjects now that the path was created</span>
        GameObject.<span class="hljs-constructor">DestroyImmediate(<span class="hljs-params">obj</span>)</span>;</code></pre></div>
<h2 id="寻路"><a href="#寻路" class="headerlink" title="寻路"></a>寻路</h2>代码文件位于Plugins文件夹下<br>其中有<strong>NavMeshUtils2D</strong>、<strong>NavMesh2D</strong>是作为静态工具类在使用，主要功能是进行二维于三维坐标之间的转换。<br>主要代码位于<strong>NavMeshAgent2D.cs</strong>中。</li>
<li>初始化<br>根据输入的参数，生成在3d下的NavMeshAgent。<div class="hljs"><pre><code class="hljs sqf"><span class="hljs-comment">// create projection</span>
        var go = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
        go.<span class="hljs-built_in">name</span> = <span class="hljs-string">&quot;NAVIGATION2D_AGENT&quot;</span>;
        go.transform.<span class="hljs-built_in">position</span> = NavMeshUtils2D.ProjectTo3D(transform.<span class="hljs-built_in">position</span>); <span class="hljs-comment">// todo height 0.5 again?</span>
        <span class="hljs-built_in">agent</span> = go.AddComponent&lt;NavMeshAgent&gt;();
        rigidbody2D = GetComponent&lt;Rigidbody2D&gt;();
        collider2D = GetComponent&lt;Collider2D&gt;();
        <span class="hljs-comment">// disable navmesh and collider (no collider for now...)</span>
        Destroy(<span class="hljs-built_in">agent</span>.GetComponent&lt;Collider&gt;());
        Destroy(<span class="hljs-built_in">agent</span>.GetComponent&lt;MeshRenderer&gt;());

        <span class="hljs-comment">// pass serialized values once</span>
        <span class="hljs-built_in">agent</span>.<span class="hljs-built_in">speed</span> = <span class="hljs-variable">_speed</span>;
        <span class="hljs-built_in">agent</span>.angularSpeed = <span class="hljs-variable">_angularSpeed</span>;
        <span class="hljs-built_in">agent</span>.acceleration = <span class="hljs-variable">_acceleration</span>;
        <span class="hljs-built_in">agent</span>.stoppingDistance = <span class="hljs-variable">_stoppingDistance</span>;
        <span class="hljs-built_in">agent</span>.autoBraking = <span class="hljs-variable">_autoBraking</span>;
        <span class="hljs-built_in">agent</span>.radius = <span class="hljs-variable">_radius</span>;
        <span class="hljs-built_in">agent</span>.obstacleAvoidanceType = <span class="hljs-variable">_quality</span>;
        <span class="hljs-built_in">agent</span>.avoidancePriority = <span class="hljs-variable">_priority</span>;
        <span class="hljs-built_in">agent</span>.autoRepath = <span class="hljs-variable">_autoRepath</span>;</code></pre></div></li>
<li>坐标转换<br>当选择2d平面上一点时，设置NavMeshAgent2Dd的destination，其会将值转换成三维坐标，赋值给该对象对应的agent。<div class="hljs"><pre><code class="hljs csharp"><span class="hljs-keyword">public</span> Vector2 destination
    &#123;
        <span class="hljs-keyword">get</span> &#123; <span class="hljs-keyword">return</span> NavMeshUtils2D.ProjectTo2D(agent.destination); &#125;
        <span class="hljs-keyword">set</span> &#123; agent.destination = NavMeshUtils2D.ProjectTo3D(<span class="hljs-keyword">value</span>); &#125;
    &#125;</code></pre></div>
在<strong>Update</strong>、<strong>LateUpdate</strong>、<strong>FixedUpdate</strong>中，将3d空间中Agent的运行结果（位置），转换到2d赋值给对象。<div class="hljs"><pre><code class="hljs pgsql"><span class="hljs-type">void</span> <span class="hljs-keyword">Update</span>()
    &#123;
        // <span class="hljs-keyword">copy</span> position: <span class="hljs-keyword">transform</span> <span class="hljs-keyword">in</span> <span class="hljs-keyword">Update</span>, rigidbody <span class="hljs-keyword">in</span> FixedUpdate
        <span class="hljs-keyword">if</span> (rigidbody2D == <span class="hljs-keyword">null</span> || rigidbody2D.isKinematic)
            <span class="hljs-keyword">transform</span>.position = NavMeshUtils2D.ProjectTo2D(agent.<span class="hljs-keyword">transform</span>.position);

        // stuck detection
        <span class="hljs-keyword">if</span> (IsStuck())
        &#123;
            // stop agent movement, <span class="hljs-keyword">reset</span> it <span class="hljs-keyword">to</span> <span class="hljs-keyword">current</span> position
            agent.ResetPath();
            agent.<span class="hljs-keyword">transform</span>.position = NavMeshUtils2D.ProjectTo3D(<span class="hljs-keyword">transform</span>.position);
            <span class="hljs-keyword">Debug</span>.Log(&quot;stopped agent because of collision in 2D plane&quot;);
        &#125;
    &#125;
    <span class="hljs-type">void</span> LateUpdate()
    &#123;
        // <span class="hljs-keyword">copy</span> position again, maybe NavMeshAgent did something <span class="hljs-built_in">new</span>
        <span class="hljs-keyword">if</span> (rigidbody2D == <span class="hljs-keyword">null</span> || rigidbody2D.isKinematic)
            <span class="hljs-keyword">transform</span>.position = NavMeshUtils2D.ProjectTo2D(agent.<span class="hljs-keyword">transform</span>.position);
    &#125;

    <span class="hljs-type">void</span> FixedUpdate()
    &#123;
        // <span class="hljs-keyword">copy</span> position: <span class="hljs-keyword">transform</span> <span class="hljs-keyword">in</span> <span class="hljs-keyword">Update</span>, rigidbody <span class="hljs-keyword">in</span> FixedUpdate
        <span class="hljs-keyword">if</span> (rigidbody2D != <span class="hljs-keyword">null</span> &amp;&amp; !rigidbody2D.isKinematic)
            rigidbody2D.MovePosition(NavMeshUtils2D.ProjectTo2D(agent.<span class="hljs-keyword">transform</span>.position));
    &#125;</code></pre></div></li>
<li>障碍物<br>原理与上方代码一致，根据2d物体建立对应的3d Obstacle，Update中进行位置转换，只不过由于是障碍物，所以是2d的坐标同步到3d空间中。<div class="hljs"><pre><code class="hljs reasonml">void <span class="hljs-constructor">Update()</span>
    &#123;
        <span class="hljs-comment">// copy properties to projection all the time</span>
        <span class="hljs-comment">// (in case they are modified after creating it)</span>
        obstacle.carving = carve;
        obstacle.center = NavMeshUtils2D.<span class="hljs-constructor">ProjectTo3D(<span class="hljs-params">center</span>)</span>;
        obstacle.size = <span class="hljs-keyword">new</span> <span class="hljs-constructor">Vector3(<span class="hljs-params">size</span>.<span class="hljs-params">x</span>, 1, <span class="hljs-params">size</span>.<span class="hljs-params">y</span>)</span>;

        <span class="hljs-comment">// scale and rotate to match scaled/rotated sprites center properly</span>
        obstacle.transform.localScale = <span class="hljs-keyword">new</span> <span class="hljs-constructor">Vector3(<span class="hljs-params">transform</span>.<span class="hljs-params">localScale</span>.<span class="hljs-params">x</span>, 1, <span class="hljs-params">transform</span>.<span class="hljs-params">localScale</span>.<span class="hljs-params">y</span>)</span>;
        obstacle.transform.rotation = Quaternion.<span class="hljs-constructor">Euler(NavMeshUtils2D.RotationTo3D(<span class="hljs-params">transform</span>.<span class="hljs-params">eulerAngles</span>)</span>);

        <span class="hljs-comment">// project position to 3d</span>
        obstacle.transform.position = NavMeshUtils2D.<span class="hljs-constructor">ProjectTo3D(<span class="hljs-params">transform</span>.<span class="hljs-params">position</span>)</span>;
    &#125;</code></pre></div></li>
</ul>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/Navigation/">Navigation</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Navigation/">Navigation</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！</p>
              
              
                <div class="post-prevnext row">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2020/10/29/NavMesh/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">NavMesh</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/10/28/%E9%98%BF%E5%B7%B4%E9%98%BF%E5%B7%B4/">
                        <span class="hidden-mobile">阿巴阿巴</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  

  

  
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>







  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '#post-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "Nav2D插件工作原理&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>















</body>
</html>
